package Level03;

import java.util.*;

/**
 * 有四种水果(苹果，香蕉，西瓜，橘子)
 * 1、给每种水果设定一个商品号，商品号是 8 个 0-9 的随机数，商品号码不能
 * 重复, 最小值 "00000001", 最大值 "99999999" 2、根据商品号查询对应的商品。
 * 如果查不到输出：“查无此商品
 */
public class Four {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("商品号是 8 个 0-9 的随机数,请输入：");
        Long nextLine = Long.parseLong(scanner.nextLine());
        //定义一个双列集合用来装编号和水果
        HashMap<Long, Object> hashMap = new HashMap<>();
        ArrayList<Object> fruit = new ArrayList<>();
        fruit.add("苹果");
        fruit.add("香蕉");
        fruit.add("西瓜");
        fruit.add("橘子");
        Random random = new Random();
        for (int i = 1; i < fruit.size()+1; i++) {
            switch (i){
                case 1:
                    long apple = random.nextInt(99999999)+1;
                    hashMap.put(apple,"苹果");
                    break;
                case 2:
                    long banana = random.nextInt(99999999)+1;
                    hashMap.put(banana,"香蕉");
                    break;
                case 3:
                    long watermelon  = random.nextInt(99999999)+1;
                    hashMap.put(watermelon,"西瓜");
                    break;
                case 4:
                    long orange = random.nextInt(99999999)+1;
                    hashMap.put(orange,"橘子");
                    break;
            }
        }
        for (Map.Entry<Long, Object> entry : hashMap.entrySet()) {
            System.out.println("随机的编号为："+entry.getKey());
            if (nextLine.equals(entry.getKey())) {
                System.out.println("编号"+nextLine+"对应的水果为："+entry.getValue());
            }
        }
        System.out.println("没有这个编号的水果");
    }
}
